package com.zheng.study.base.service.impl;

import com.zheng.study.base.dao.MongoBaseDao;
import com.zheng.study.base.entity.MongoEntity;
import com.zheng.study.base.service.MongoBaseService;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.core.query.Update;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * mongodb Service实现类基类
 * ============================================================================
 * author : fallenpanda
 * createDate:  2016-07-19 。
 * ============================================================================
 */
@Service
public abstract class MongoBaseServiceImpl<T extends MongoEntity, PK extends Serializable> implements MongoBaseService<T,PK> {

	private MongoBaseDao<T, PK> mongoBaseDao;

	public abstract MongoBaseDao<T, PK> getMongoBaseDao();

	public void setMongoBaseDao(MongoBaseDao<T, PK> mongoBaseDao) {
		this.mongoBaseDao = mongoBaseDao;
	}

	public List<T> find(Query query) {
		return getMongoBaseDao().find(query);
	}

	public T findOne(Query query) {
		return getMongoBaseDao().findOne(query);
	}

	public void update(Query query, Update update) {
		getMongoBaseDao().update(query,update);
	}

	public T save(T entity) {
		return getMongoBaseDao().save(entity);
	}

	public T findById(String id) {
		return getMongoBaseDao().findById(id);
	}

	public T findById(String id, String collectionName) {
		return getMongoBaseDao().findById(id,collectionName);
	}

	public long count(Query query) {
		return getMongoBaseDao().count(query);
	}

}
